package com.ma.admin.model

import com.ma.admin.handler.UserDataProxy
import org.hibernate.annotations.DynamicUpdate
import xyz.erupt.annotation.Erupt
import xyz.erupt.annotation.EruptField
import xyz.erupt.annotation.sub_erupt.Power
import xyz.erupt.annotation.sub_field.Edit
import xyz.erupt.annotation.sub_field.EditType
import xyz.erupt.annotation.sub_field.View
import xyz.erupt.annotation.sub_field.sub_edit.DateType
import xyz.erupt.annotation.sub_field.sub_edit.InputType
import xyz.erupt.annotation.sub_field.sub_edit.Search
import java.io.Serializable
import java.util.*
import javax.persistence.*

/**
 * 用户管理
 *
 * @author yong
 * @date 2021/2/2 16:15
 */
@Entity
@DynamicUpdate
@Erupt(name = "用户",
        primaryKeyCol = "user_id",
        power = Power(add = false, delete = true, edit = true, query = true),
        dataProxy = [UserDataProxy::class]
)
@Table(name = "user")
class User : Serializable {
    @EruptField
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "user_id")
    var userId: Int = -1

    @EruptField(
            views = [View(title = "用户名", sortable = true)],
            edit = Edit(title = "用户名", type = EditType.INPUT, notNull = true, search = Search(), inputType = InputType()
            )
    )
    @Column(name = "user_login_name")
    var userLoginName: String = ""

    @EruptField(
            views = [View(title = "手机号")],
            edit = Edit(title = "手机号", type = EditType.INPUT, search = Search(), inputType = InputType())
    )
    @Column(name = "user_phone")
    var userPhone: String = ""

    @EruptField(
            views = [View(title = "性别")],
            edit = Edit(title = "性别", type = EditType.INPUT, search = Search(), inputType = InputType())
    )
    @Column(name = "user_sex")
    var userSex: String = ""

    @EruptField(
            views = [View(title = "邮箱")],
            edit = Edit(title = "邮箱", type = EditType.INPUT, notNull = true, search = Search(),
                    inputType = InputType(type = "email"))
    )
    @Column(name = "user_email")
    var userEmail: String = ""

    @EruptField(
            views = [View(title = "生日")],
            edit = Edit(title = "生日", type = EditType.DATE, search = Search(vague = true),
                    dateType = DateType(pickerMode = DateType.PickerMode.HISTORY))
    )
    @Column(name = "user_birth")
    var userBirth: Date? = null

    @EruptField(
            views = [View(title = "身份证号")],
            edit = Edit(title = "身份证号", type = EditType.INPUT, search = Search(), inputType = InputType())
    )
    @Column(name = "user_identity_num")
    var userIdentityNum: String = ""
}